<template>
  <view>
    <!-- 头像和立即登录 -->
    <view class="userinfo">
      <!-- 未登录状态样式 -->
      <view class="userinfo-image" v-if="userinfo==null">
        <image src="../../static/imag/icon_a1.png"></image>
        <button class="btn" open-type="getUserInfo" @getuserinfo="getUserInfo">
          立即登录
        </button>
      </view>

      <!-- 登录状态 -->
      <view class="message" v-else>
        <!-- 用户头像昵称 -->
        <view class="message-user">
          <!-- 左侧头像昵称 -->
          <view class="user-left">
            <!-- 头像 -->
            <view class="user-image">
              <image :src="userinfo.avatarUrl"></image>
            </view>
            <!-- 名称 -->
            <view class="user-nikename">
              <view style="font-size: 34rpx;font-weight: 700;">
                {{userinfo.nickName}}
              </view>
              <view class="name">
                <navigator url="../../subpkg/attention/attention" style="margin-right: 20rpx;">
                  <text class="mag">0</text>
                  <text>关注</text>
                </navigator>
                <navigator url="../../subpkg/attention/attention?type=2">
                  <text class="mag">0</text> <text>粉丝</text>
                </navigator>
              </view>
            </view>
          </view>
          <!-- 右侧签到跟消息 -->
          <view class="user-right">
            <!-- 跳转任务中心 -->
            <navigator url="../../subpkg/task/task" class="signIn">已签到</navigator>
            <!-- 跳转消息页面 -->
            <navigator url="../../subpkg/information/information">
              <text class="iconfont icon-icon-" style="font-size: 60rpx;"></text>
            </navigator>
          </view>
        </view>
        <!-- 用户信息 -->
        <view class="message-state">
          <view class="message-taskbar">
            <text>0</text>
            <text>动态</text>
          </view>
          <view class="message-taskbar">
            <text>0</text>
            <text>点赞</text>
          </view>
          <navigator url="../../subpkg/collect/collect" class="message-taskbar">
            <text>0</text>
            <text>收藏</text>
          </navigator>
          <navigator url="../../subpkg/detail/detail" class="message-taskbar">
            <text>0.70</text>
            <text>积分</text>
          </navigator>
        </view>
      </view>


      <!-- 分类开始 -->
      <view class="classify">
        <!-- 积分提现 -->
        <navigator url="../../subpkg/integral/integral" class="classify-image">
          <text class="iconfont icon-tixian"></text>
          <text>积分提现</text>
        </navigator>
        <!-- 积分明细 -->
        <navigator url="../../subpkg/detail/detail" class="classify-image">
          <text class="iconfont icon-mingxi"></text> <text>积分明细</text>
        </navigator>
        <!-- 我的推荐 -->
        <navigator url="../../subpkg/recommend/recommend" class="classify-image">
          <text class="iconfont icon-url"></text>
          <text>我的推荐</text>
        </navigator>
        <!-- 积分规则 -->
        <navigator url="../../subpkg/rule/rule" class="classify-image">
          <text class="iconfont icon-mingxi1"></text>
          <text>积分规则</text>
        </navigator>
      </view>
      <!-- 分类结束 -->
    </view>


    <!-- 操作开始 -->
    <view class="operation">
      <!-- 上传表情 -->
      <navigator url="../../subpkg/expression/expression" class="select">
        <view class="select-image">
          <text class="iconfont icon-shangchuan"></text>
          <text>上传表情</text>
        </view>
        <uni-icons type="arrowright" size="16"></uni-icons>
      </navigator>
      <!-- 我的上传 -->
      <navigator url="../../subpkg/myUploading/myUploading" class="select">
        <view class="select-image">
          <text class="iconfont icon-wenjian"></text>
          <text>我的上传</text>
        </view>
        <uni-icons type="arrowright" size="16"></uni-icons>
      </navigator>
      <!-- 我的订单 -->
      <view class="select" @click="myOrder">
        <view class="select-image">
          <text class="iconfont icon-guize"></text>
          <text>我的订单</text>
        </view>
        <uni-icons type="arrowright" size="16"></uni-icons>
      </view>
      <!-- 我的消息 -->
      <navigator url="../../subpkg/information/information" class="select">
        <view class="select-image">
          <text class="iconfont icon-icon-"></text>
          <text>我的消息</text>
        </view>
        <uni-icons type="arrowright" size="16"></uni-icons>
      </navigator>
      <!-- 公众号 -->
      <navigator url="../../subpkg/public/public" class="select">
        <view class="select-image">
          <text class="iconfont icon-weixin"></text>
          <text>公众号</text>
        </view>
        <uni-icons type="arrowright" size="16"></uni-icons>
      </navigator>
      <!-- 联系客服 -->
      <button class="select" open-type="contact" hover-class='none'>
        <view class="select-image">
          <text class="iconfont icon-kefu"></text>
          <text>联系客服</text>
        </view>
        <uni-icons type="arrowright" size="16"></uni-icons>
      </button>
      <!-- 用户协议 -->
      <navigator url="../../subpkg/agreement/agreement" class="select">
        <view class="select-image">
          <text class="iconfont icon-jinggao"></text>
          <text>用户协议</text>
        </view>
        <uni-icons type="arrowright" size="16"></uni-icons>
      </navigator>
      <!-- 清楚缓存 -->
      <view class="select" @click="removedCache">
        <view class="select-image">
          <text class="iconfont icon-shezhi"></text>
          <text>清除缓存</text>
        </view>
        <uni-icons type="arrowright" size="16"></uni-icons>
      </view>
    </view>
    <!-- 操作结束 -->
    <TabBar tabIndex=4></TabBar>
  </view>
</template>

<script>
  import TabBar from '../../components/jinjie-tabbar/jinjie-tabbar.vue'

  export default {
    components: {
      TabBar
    },
    data() {
      return {
        userinfo: null
      };
    },
    onLoad() {
      console.log(this.userinfo)
    },
    methods: {
      // 获取用户信息
      getUserInfo(e) {
        // 判断是否获取用户信息成功
        if (e.detail.errMsg === 'getUserInfo:fail auth deny') return this.$api.msg('您取消了登录授权！')
        // 将用户的信息存起来
        this.$api.set('userinfo', JSON.stringify(e.detail.userInfo))
        // 取出存的用户信息
        this.userinfo = JSON.parse(this.$api.get('userinfo'))
      },

      // 点击清除缓存数据
      removedCache() {
        uni.showModal({
          content: '确定清除缓存数据吗？',
          cancelText: '取消',
          confirmText: '确定',
          success: res => {
            if (res.confirm) {
              console.log('用户点击确定');
              this.$api.remove('userinfo')
              this.userinfo = null
            } else if (res.cancel) {
              console.log('用户点击取消');
            }
          }
        })
      },
      // 点击跳转京东
      myOrder() {
        uni.showModal({
          content: '即将打开"京东购物"小程序',
          cancelText: '取消',
          confirmText: '允许',
          success: res => {
            if (res.confirm) {
              console.log('用户点击允许');
            } else if (res.cancel) {
              console.log('用户点击取消');
            }
          }
        })
      }
    }
  }
</script>

<style lang="scss">
  .userinfo {
    background-color: #fdd201;
    height: 380rpx;

    position: relative;

    // 未登录状态样式
    .userinfo-image {
      display: flex;
      flex-direction: column;
      align-items: center;
      padding-top: 20rpx;

      image {
        width: 100rpx;
        height: 100rpx;
        margin-bottom: 20rpx;
      }

      // 立即登录按钮
      .btn {
        width: 160rpx;
        height: 60rpx;
        font-size: 24rpx;
        border-radius: 8rpx;
        text-align: center;
        line-height: 60rpx;
        background-color: #fff;

      }
    }

    // 登录状态
    .message {
      width: 100%;
      padding: 0 30rpx;

      // 头像昵称
      .message-user {
        height: 200rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;

        // 左侧头像昵称
        .user-left {
          display: flex;

          .user-image {
            width: 100rpx;
            height: 100rpx;
            margin-right: 30rpx;
          }

          .user-nikename {
            display: flex;
            flex-direction: column;
            justify-content: space-between;

            .name {
              display: flex;
              font-size: 24rpx;

              .mag {
                display: inline-block;
                margin-right: 10rpx;
                font-size: 30rpx;
                font-size: 700;
              }
            }
          }
        }

        // 右侧签到跟消息
        .user-right {
          font-size: 24rpx;
          display: flex;
          align-items: center;

          .signIn {
            margin-right: 40rpx;
            width: 120rpx;
            height: 50rpx;
            text-align: center;
            line-height: 60rpx;
            border-radius: 30rpx;
            background-color: #fff;
          }
        }
      }

      // 用户信息
      .message-state {
        height: 180rpx;
        display: flex;
        justify-content: space-between;

        .message-taskbar {
          flex: 1;
          display: flex;
          flex-direction: column;
          align-items: center;

          text {
            display: inline-block;
          }
        }
      }
    }
  }

  // 分类
  .classify {
    width: 690rpx;
    background-color: #fff;
    height: 140rpx;
    font-size: 24rpx;
    display: flex;
    justify-content: space-between;
    position: absolute;
    top: 77%;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16rpx;


    .classify-image {
      width: 25%;
      padding: 20rpx 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;

      image {
        width: 66rpx;
        height: 66rpx;
      }

      text:nth-child(1) {
        font-size: 50rpx;
      }
    }
  }

  // 操作开始
  .operation {
    margin: 90rpx 30rpx 0;
    background-color: #fff;
    height: 800rpx;
    padding: 0 30rpx;
    border-radius: 16rpx;


    .select {
      height: 100rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid #f0f0f0;

      .select-image {
        display: flex;
        align-items: center;

        text:nth-child(1) {
          font-size: 30rpx;
          margin-right: 20rpx;
        }
      }
    }
  }
</style>
